package geektime.spring.springbucks;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;


@Slf4j
@SpringBootApplication
@EnableFeignClients
public class Task2_Q3_Application implements CommandLineRunner {

	@Autowired
	private RestTemplate restTemplate;
	public static void main(String[] args) {
		SpringApplication.run(Task2_Q3_Application.class, args);
	}

	@Override
	public void run(String... args) throws Exception {

		String uri = "http://localhost:8080/coffee/getJson/1";

		String response = HttpUtil.get(uri, CharsetUtil.CHARSET_UTF_8);

		ResponseEntity<String> responseEntity=restTemplate.getForEntity(uri, String.class);

		System.out.println(response + responseEntity);
	}

	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

}

